﻿//Write a program that exchanges bits 3, 4 and 5 with bits 24, 25 and 26 of given 32-bit unsigned integer.

using System;

class ExchangesBits
{
    static void Main()
    {
        Console.Write("Enter unsigned integer number: ");
        string inputNumberString = Console.ReadLine();

        uint number;
        if (uint.TryParse(inputNumberString, out number))
        {
            Console.WriteLine("Old number value: {0, -10} ({1})", number, Convert.ToString(number, 2).PadLeft(32, '0'));

            //shift 3,4 and 5 bits at the begining and get only them.
            byte firstThreeBits = (byte)((number >> 3) & 7); //7 -> 111
            //shift 24,25 and 26 bits at the begining and get only them.
            byte secondThreeBits = (byte)((number >> 24) & 7); //7 -> 111

            byte firstXORsecond = (byte)(firstThreeBits ^ secondThreeBits);
            uint firstAndSecondXOR = (uint)((firstXORsecond << 24) | (firstXORsecond << 3));
            number = number ^ firstAndSecondXOR;
            Console.WriteLine("New number value: {0, -10} ({1})", number, Convert.ToString(number, 2).PadLeft(32, '0'));
        }
        else
            Console.WriteLine("Wrong number type (Expected UInt).");
    }
}
